package model;

import java.util.concurrent.CountDownLatch;

public class State {
	private int numFeet;
	private boolean[] awake;
	private int[] coord;
	private int turn = 0;
	public CountDownLatch feetReady;
	public CountDownLatch headReady = new CountDownLatch(1);
	
	State(int numFeet) {
		this.numFeet = numFeet;
		
		awake = new boolean[numFeet];
		coord = new int[numFeet];
		feetReady = new CountDownLatch(numFeet);
		for(int i = 0; i < numFeet; i++) {
			awake[i] = false;
			coord[i] = 0;
		}
		
				
	}
	
	public int numFeet() {
		return numFeet;
	}
	
	public void wake() {
		awake[turn] = true;
	}
	
	public boolean activeness(int id) {
		if(0 <= id && id <= numFeet) {
			return awake[id];
		}
		return false;
	}
	
	public int turn() {
		return turn;
	}
	
	public boolean changeTurn() {
		if(coord[0] == coord[1]) {
			turn = (turn + 1) % numFeet;
		}
		
		return coord[0] == coord[1];
	}
	
	public void step() {
			++coord[turn];
			turn = (turn + 1) % numFeet;
	}
	
	public String getCoords() {
		return "(" + coord[0] + ", " + coord[1] + ")"; 
	}

}